package com.ruoyi.recipes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.recipes.domain.DifficultyOptions;
import com.ruoyi.recipes.service.IDifficultyOptionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 难度选项Controller
 * 
 * @author syy
 * @date 2025-08-12
 */
@RestController
@RequestMapping("/recipes/options")
public class DifficultyOptionsController extends BaseController
{
    @Autowired
    private IDifficultyOptionsService difficultyOptionsService;

    /**
     * 查询难度选项列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:list')")
    @GetMapping("/list")
    public TableDataInfo list(DifficultyOptions difficultyOptions)
    {
        startPage();
        List<DifficultyOptions> list = difficultyOptionsService.selectDifficultyOptionsList(difficultyOptions);
        return getDataTable(list);
    }

    /**
     * 导出难度选项列表
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:export')")
    @Log(title = "难度选项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DifficultyOptions difficultyOptions)
    {
        List<DifficultyOptions> list = difficultyOptionsService.selectDifficultyOptionsList(difficultyOptions);
        ExcelUtil<DifficultyOptions> util = new ExcelUtil<DifficultyOptions>(DifficultyOptions.class);
        util.exportExcel(response, list, "难度选项数据");
    }

    /**
     * 获取难度选项详细信息
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(difficultyOptionsService.selectDifficultyOptionsById(id));
    }

    /**
     * 新增难度选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:add')")
    @Log(title = "难度选项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DifficultyOptions difficultyOptions)
    {
        return toAjax(difficultyOptionsService.insertDifficultyOptions(difficultyOptions));
    }

    /**
     * 修改难度选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:edit')")
    @Log(title = "难度选项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DifficultyOptions difficultyOptions)
    {
        return toAjax(difficultyOptionsService.updateDifficultyOptions(difficultyOptions));
    }

    /**
     * 删除难度选项
     */
    @PreAuthorize("@ss.hasPermi('recipes:options:remove')")
    @Log(title = "难度选项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(difficultyOptionsService.deleteDifficultyOptionsByIds(ids));
    }
}
